﻿/*
7-35 有理数均值 (20 分)
本题要求编写程序，计算N个有理数的平均值。

输入格式：
输入第一行给出正整数N（≤100）；第二行中按照a1/b1 a2/b2 …的格式给出N个分数形式的有理数，其中分子和分母全是整形范围内的整数；如果是负数，则负号一定出现在最前面。

输出格式：
在一行中按照a/b的格式输出N个有理数的平均值。注意必须是该有理数的最简分数形式，若分母为1，则只输出分子。

输入样例1：
4
1/2 1/6 3/6 -5/10
输出样例1：
1/6
输入样例2：
2
4/3 2/3
输出样例2：
1
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef long long i8;
typedef struct _Rational {
	i8 head;
	i8 numerator;
	i8 denominator;
} Rational, * PRational;
static PRational rational_refine(PRational a);

i8 gcd(i8 a, i8 b) {
	i8 c;
	if (b > a)
	{
		c = a;
		a = b;
		b = c;
	}
	c = a % b;
	while (c) {
		a = b;
		b = c;
		c = a % b;
	}
	return b;
}

static void rational_read(PRational r) {
	r->head = 0;
	scanf("%lld/%lld", &(r->numerator), &(r->denominator));
	rational_refine(r);
}

static void rational_print(PRational r) {
	if (r->numerator != 0)
		printf("%lld/%lld\n", (r->numerator + r->head * r->denominator), (r->denominator));
	else
		printf("%lld\n", r->head);
}

static PRational rational_refine(PRational a) {
	if (a->numerator != 0) {
		i8 d = gcd(a->denominator, a->numerator);
		if (d > 1)
		{
			a->numerator /= d;
			a->denominator /= d;
		}
		a->head += a->numerator / a->denominator;
		a->numerator %= a->denominator;
	}
	return a;
}

static Rational rational_add(PRational a, PRational b) {
	Rational c = {};
	i8 d = gcd(a->denominator, b->denominator);
	c.numerator = b->denominator /d * a->numerator + a->denominator / d * b->numerator;
	c.denominator = a->denominator /d  * b->denominator;
	c.head = a->head + b->head;
	rational_refine(&c);
	return c;
}

int main() {
	freopen("D:/Develop/GitRepos/MOOC/浙江大学/数据结构/201906/zju_C_Basic/data/7.35.txt", "r", stdin);
	int n=0;
	Rational a = {};
	Rational b = {};
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		rational_read(&b);
		if (a.denominator == 0)
			a = b;
		else {
			a = rational_add(&a, &b);
		}
	}
	b.head = 0;
	b.denominator = n;
	b.numerator = a.head;
	rational_refine(&b);
	a.head = 0;
	a.denominator *= n;
	a = rational_add(&a, &b);
	rational_print(&a);
	return 0;
}